/**
 * Flickr collection
 * @param {Flickr.Collection} api response from Flickr API call
 * @param {Tree} tree TreeObject collection will be added to
 * @param {Boolean} [root = false] whether collection is at the root
 * @constructor
 */
function Collection(api, tree, root)
{
	"use strict";

	/** @type {Collection} */
	var _parent = this;

	this.id = api.id.replace(/^(\d+)\-/, '');   // remove database prefix
	this.title = Format.text(api.title);
	this.description = Format.text(api.description);
	/** @type Array.<Collection> */
	this.collections = [];		// local arrays for quick listing
	/** @type Array.<Set> */
	this.sets = [];
	this.atRoot = root;

	function init()
	{
		/** @type {Number} */
		var i;

		for (i in api.collection)
		{
			_parent.collections.push(new Collection(api.collection[i], tree));
		}

		for (i in api.set)
		{
			// use already constructed set if one exists
			var set = tree.setWithID(api.set[i].id);
			if (set == null) { set = new Set(api.set[i]); }
			_parent.sets.push(set);
		}
	}

	init();
}
